package com.example.occlusiondemo.animation;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;

/**
 * 安卓视图属性动画
 * <p>UI交互的动画控制</p>
 * <pre>SampleCode:
 * </pre>
 *
 * @author tanyx 2022/9/21
 * @version 1.0
 **/
public class ViewAnimation {

    /**
     * 属性查询-属性框弹出动画
     * @param view
     * @param duration
     * @return
     */
    public static View viewExpandClick(View view, long duration){
        ObjectAnimator translationX = ObjectAnimator.ofFloat(
                view, "scaleX", 0.5f,1.2f,1);
        ObjectAnimator translationY = ObjectAnimator.ofFloat(
                view, "scaleY", 0.5f,1.2f,1);
        AnimatorSet animatorSet=new AnimatorSet();
        animatorSet.setDuration(duration);
        animatorSet.playTogether(translationX, translationY);
        animatorSet.start();
        return view;
    }

    /**
     * 按钮点击动画
     * @param view
     * @param duration
     * @return
     */
    public static View viewExpandClick2(View view, long duration){
        ObjectAnimator translationX = ObjectAnimator.ofFloat(
                view, "scaleX", 0.8f,1.5f,1);
        ObjectAnimator translationY = ObjectAnimator.ofFloat(
                view, "scaleY", 0.8f,1.5f,1);
        AnimatorSet animatorSet=new AnimatorSet();
        animatorSet.setDuration(duration);
        animatorSet.playTogether(translationX, translationY);
        animatorSet.start();
        return view;
    }

    /**
     * 视口模式-参数设置栏弹出动画
     * @param view
     * @param duration
     * @return
     */
    public static View viewUp(View view, long duration){
        ObjectAnimator translationY = ObjectAnimator.ofFloat(
                view, "scaleY", 0.5f,1);
        translationY.start();
        return view;
    }

    /**
     * 二级菜单弹出动画
     * @param view
     * @param duration
     * @return
     */
    public static View viewLeft(View view, long duration){
        ObjectAnimator translationY = ObjectAnimator.ofFloat(
                view, "scaleX", 0.5f,1);
        translationY.start();
        return view;
    }
    public static void viewMove1(View view){
        ObjectAnimator translationY = ObjectAnimator.ofFloat(
                view, "translationY", 0, -150);
        ObjectAnimator translationX = ObjectAnimator.ofFloat(
                view, "translationX", 0, 360);
        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1, 0);
        AnimatorSet animatorSet=new AnimatorSet();
        animatorSet.setDuration(200);
        animatorSet.playTogether(alpha,translationY,translationX);
        animatorSet.start();
    }
    public static void viewMove2(View view){
        ObjectAnimator translationY = ObjectAnimator.ofFloat(
                view, "translationY", -150, 0);
        ObjectAnimator translationX = ObjectAnimator.ofFloat(
                view, "translationX", 360, 0);
        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 0, 1);
        AnimatorSet animatorSet=new AnimatorSet();
        animatorSet.setDuration(200);
        animatorSet.playTogether(alpha,translationY,translationX);
        animatorSet.start();
    }
}
